package com.example.common.Exception;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//类变成一个全局的异常处理器，可以自动扫描并捕获所有控制器类,@RestController 或 @Controller）中抛出的异常。
public class GlobalExceptionHandler {    //封装管理其他异常的类


    @ExceptionHandler(OtherException.class)
    public String handleCustomOtherException(OtherException ex) {
        String Other = "后端问题: " + ex.getMessage();
        return Other;
    }

    @ExceptionHandler(TokenException.class)
    public String handleCustomTokenException(TokenException ex) {
        String error = "Token错误: " + ex.getMessage();
        return error;
    }


}

